﻿using System.Linq;

namespace Sample
{
	using System.Windows;

	using Ecng.Common;

	using StockSharp.BusinessEntities;

	public partial class NewOrderWindow
	{
		public NewOrderWindow()
		{ 
			InitializeComponent();
//			Portfolio.Trader = MainWindow.Instance.Trader;
            x_Security.ItemsSource = MainWindow.Instance.Trader.Securities;
            x_Portfolio.ItemsSource = MainWindow.Instance.Trader.Portfolios;
		    x_Volume.Text = "1";
    //        x_Price = x_Security.ItemsSource.
		}

//		public Security Security { get; set; }

		private void SendClick(object sender, RoutedEventArgs e)
		{
			var order = new Order
			{
//				Portfolio = Portfolio.SelectedPortfolio,
                Portfolio = (Portfolio)x_Portfolio.SelectedItem,
				Volume = x_Volume.Text.To<decimal>(),
				Price = x_Price.Text.To<decimal>(),
//				Security = Security,
                Security = (Security)x_Security.SelectionBoxItem,
  //              Security = (Security)MainWindow.Instance.Trader.Securities.FirstOrDefault(s => s.Code == "LKOH"),
				Direction = x_IsBuy.IsChecked == true ? OrderDirections.Buy : OrderDirections.Sell,
			};
			
			MainWindow.Instance.Trader.RegisterOrder(order);
			DialogResult = true;
		}
	}
}
